import { defineComponent } from "vue";
import { useRouter } from "vue-router";

import Template from '@/models/template'

import path from 'path'
const { Sequelize } = window.require('sequelize-typescript');
import * as db_context from '@/models/db_context'


export default defineComponent(() => {
  const router = useRouter()
  console.log('111111111111111111111111');

  /*
  
*/

const onClickDb = () => {
  console.log('111');
  db_context.Template
  .getList<db_context.Template>()
  .then(results => {
      console.log('resultsxxxxx:',results);
  });

  console.log('2222');
}

const onClickLeft = () => {
  console.log('111');
  
 
    
    console.log('222222');
   const sequelize = new Sequelize({

    dialect: 'sqlite',
    pool: {
      max: 5,
      min: 0,
      idle: 10000
    },
    define: {
        timestamps: false,
        createdAt: "CreatedAt",  //自定义时间戳
        updatedAt: "UpdatedAt", // 自定义时间戳
    },
    storage: "./test.db",
    //modelPaths: [__dirname + '/ef_models/tables'],
  
    });

    
//sequelize.addModels([path.resolve(__dirname, `./models/`)])

  //sequelize.addModels([__dirname +`./models/`]);
  sequelize.addModels([Template]) 
    
sequelize.authenticate().then(() => {
  console.log('Connection has been established successfully.')
})
.catch((err:any) => {
  console.error('Unable to connect to the database:', err)
});

// 查询


//db_context.TemplateTable
//.getList<db_context.TemplateTable>()
//.then(results => {
//    console.log('results:',results);
//});


 Template.getList<Template>().then((result: any) => {
  console.log('result:ggg',result)
});



sequelize.query("select * from template ", { type: sequelize.QueryTypes.SELECT}).then((result: any) => {
  console.log('result:',result)
});

}
   

  return () => {
    return (
      <div class="pd-nav" style="background:#f7f8fa;min-height:100vh">
         
        <button onClick={onClickLeft}>1111111</button>
        <button onClick={onClickDb}>2222222</button>
        
      </div >
    );
  }
})